﻿import request from '/@/utils/request';
enum Api {
	Addcar_case = '/api/car_case/add',
	Deletecar_case = '/api/car_case/delete',
	Updatecar_case = '/api/car_case/update',
	Pagecar_case = '/api/car_case/page',
	Getcar_carDropdown = '/api/car_case/car_carDropdown',
	Uploadcoverurl = '/api/car_case/Uploadcoverurl',
	Getcar_color2Dropdown = '/api/car_case/car_color2Dropdown',
	Getcar_zhiganDropdown = '/api/car_case/car_zhiganDropdown',
	GetTreeOutputTreeOutputDropdown = '/api/car_case/TreeOutputTreeOutputDropdown',
	Getcar_SeXiDropdown = '/api/car_case/car_SeXiDropdown',
	car_colorDropdown = "/api/car_case/car_colorDropdown"
}

// 增加案例
export const addcar_case = (params?: any) =>
	request({
		url: Api.Addcar_case,
		method: 'post',
		data: params,
	});

// 删除案例
export const deletecar_case = (params?: any) =>
	request({
		url: Api.Deletecar_case,
		method: 'post',
		data: params,
	});

// 编辑案例
export const updatecar_case = (params?: any) =>
	request({
		url: Api.Updatecar_case,
		method: 'post',
		data: params,
	});

// 分页查询案例
export const pagecar_case = (params?: any) =>
	request({
		url: Api.Pagecar_case,
		method: 'post',
		data: params,
	});

export const getcar_carDropdown = () =>
	request({
		url: Api.Getcar_carDropdown,
		method: 'get'
	});
/**
* 上传封面图 
*/

export const uploadcoverurl = (params: any) =>
	uploadFileHandle(params, Api.Uploadcoverurl)
export const getcar_color2Dropdown = () =>
	request({
		url: Api.Getcar_color2Dropdown,
		method: 'get'
	});
export const getcar_colorDropdown = () =>
	request({
		url: Api.car_colorDropdown,
		method: 'get'
	});


export const getcar_zhiganDropdown = () =>
	request({
		url: Api.Getcar_zhiganDropdown,
		method: 'get'
	});
export const getTreeOutputTreeOutputDropdown = () =>
	request({
		url: Api.GetTreeOutputTreeOutputDropdown,
		method: 'get'
	});
export const getcar_SeXiDropdown = () =>
	request({
		url: Api.Getcar_SeXiDropdown,
		method: 'get'
	});

export const uploadFileHandle = (params: any, url: string) => {
	const formData = new window.FormData();
	formData.append('file', params.file);
	//自定义参数
	if (params.data) {
		Object.keys(params.data).forEach((key) => {
			const value = params.data![key];
			if (Array.isArray(value)) {
				value.forEach((item) => {
					formData.append(`${key}[]`, item);
				});
				return;
			}
			formData.append(key, params.data![key]);
		});
	}
	return request({
		url: url,
		method: 'POST',
		data: formData,
		headers: {
			'Content-type': 'multipart/form-data;charset=UTF-8',
			// ts-ignore
			ignoreCancelToken: true,
		},
	});
};
